home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / SML⁄NJ 93+ / Documentation / examples / awk / stringtab.sml < prev    next >
Encoding:
Text File  |  1995-12-30  |  556 b   |  22 lines  |  [TEXT/R*ch]

  1. (* stringtab.sml *)
  2.  
  3. functor StringTable(type elem val default: elem) = 
  4. struct
  5.  
  6.   type awkTable = elem ref Stringmap.stringmap
  7.  
  8.   fun new() = Stringmap.new(): awkTable
  9.  
  10.   fun set (t: awkTable) (s:string, x:elem) : unit =
  11.       let val r = Stringmap.map t s in r := x end
  12.       handle Stringmap.Stringmap => Stringmap.add t (s,ref x)
  13.  
  14.   fun get (t: awkTable) (s:string) : elem =
  15.       !(Stringmap.map t s)
  16.       handle Stringmap.Stringmap => default
  17.  
  18.   fun app (t: awkTable) (f: string * elem -> unit) =
  19.       Stringmap.app (fn (s,ref e) => f(s,e)) t
  20.  
  21. end
  22.